﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIT.Controls;

namespace UIT.Animations
{
    public interface IAnimation : IContainable<StoryBoard>, IDisposable
    {
        TimeSpan Duration { get; set; }

        event EventHandler Stating;
        event EventHandler Started;
        event EventHandler Finished;

        IControl Target { get; set; }
        string TargetStyleProperty { get; set; }

        bool IsRelative { get; }
    }
    public interface IAnimation<T> : IAnimation
    {
        T By { get; }
        T To { get; }
    }

    public class Animation : IAnimation
    {
        public Animation()
        {
            Duration = new TimeSpan(0, 0, 0, 0, 500);
        }

        public StoryBoard Parent
        {
            get;
            set;
        }

        public void Dispose()
        {
            Stating = null;
            Started = null;
            Finished = null;
        }

        public bool IsRelative { get; set; }

        public TimeSpan Duration
        {
            get;
            set;
        }

        public event EventHandler Stating;

        public event EventHandler Started;

        public event EventHandler Finished;

        private IControl target;
        private string targetStyleProperty;

        public IControl Target
        {
            get
            {
                if (target == null && Parent != null)
                    return Parent.Target;
                return target;
            }
            set { target = value; }
        }

        public string TargetStyleProperty
        {
            get
            {
                if (targetStyleProperty == null && Parent != null)
                    return Parent.TargetStyleProperty;
                return targetStyleProperty;
            }
            set { targetStyleProperty = value; }
        }
    }
}
